package com.jz.main.io.leetcode;

public class Test {
    public long numberOfPairs(int[] nums1, int[] nums2, int k) {
        int c = 0;
        for (int i : nums1) {
            for (int j : nums2) {
                int b = 0;
                if(k == 1){
                    if(i==j || (i/2 >=j && i%j==0)){
                        c++;
                    }
                }else if(i>j && i>=(b=j*k)){
                    if(i==b){
                        c++;
                    }else if(i/2 >=b && i%b==0){
                        c++;
                    }
                }
            }
        }
        return c;
    }

//    public static void main(String[] args) {
//        int[] nums1 = {1,3,4};
//        int[] nums2 = {1,3,4};
//        int k = 1;
//        System.out.println(new Test().numberOfPairs(nums1,nums2,k));
//        nums1 = new int[]{1,2,4,12};
//        nums2 = new int[]{2,4};
//        k = 3;
//        System.out.println(new Test().numberOfPairs(nums1,nums2,k));
//    }

    public String compressedString(String word) {
        if(word != null){
            String s = new String("");
            char[] chars = word.toCharArray();
            char[] charsTar = new char[chars.length*2];
            int index = 0;
            char count = 49; // 计数
            char max = 57; // 计数
            char curs = chars[index]; // 游标
            for (int i = 1; i < chars.length; i++) {
                char t = chars[i];
                if(t != curs){
                    charsTar[index] = count;
                    charsTar[index+1] = curs;
                    count = 49;
                    curs = t;
                    index+=2;
                }else if(count==max){
                    charsTar[index] = count;
                    charsTar[index+1] = curs;
                    count = 49;
                    curs = t;// 可以不赋值
                    index+=2;
                }else{
                    count++;
                }
            }
            charsTar[index] = count;
            charsTar[index+1] = curs;
            chars = new char[index+2];
            for (int i = 0; i < chars.length; i++) {
                chars[i] = charsTar[i];
            }
            return new String(chars);
        }
        return "";
    }

    public static void main(String[] args) {
        String str = "abcde";
        System.out.println(new Test().compressedString(str));
        str = "aaaaaaaaaaaaaabb";
        System.out.println(new Test().compressedString(str));
    }


}
